package cn.hacynn.nd.mapper;

import cn.hacynn.nd.pojo.entity.File;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author Hacynn
 * @Date 2024/5/25 17:53
 * @Version 1.0
 */
@Mapper
public interface FileMapper extends BaseMapper<File> {

    /**
     * 根据用户id和父路径查找文件id
     * @param prefix 父路径
     * @param userId 用户id
     * @return
     */
    @Select("select id from file where user_id = #{userId} and oss_path = #{prefix}")
    String getIdByPrefix(String prefix, Long userId);

    /**
     * 根据oss路径查询文件
     * @param userId
     * @param ossPath
     * @return
     */
    @Select("select * from file where user_id = #{userId} and oss_path = #{ossPath}")
    File getFileByPath(Long userId, String ossPath);

    /**
     * 根据前缀获取文件列表
     * @param prefix
     * @param userId
     * @return
     */
    List<File> getByPrefix(String prefix, Long userId);

    /**
     * 根据用户id查询保险箱中的文件列表
     * @param userId
     * @return
     */
    @Select("select * from file where user_id = #{userId} and in_safe = 1 and deleted = false")
    List<File> getSafeFileByUserId(Long userId);

    /**
     * 根据文件夹id查询属于该文件夹的文件列表
     * @param userId
     * @param parentId
     * @return
     */
    @Select("select * from file where user_id = #{userId} and parent_id = #{parentId}")
    List<File> getChildFilesById(Long userId, String parentId);

    /**
     * 根据文件名查找文件
     * @param userId
     * @param newName
     * @return
     */
    @Select("select * from file where user_id = #{userId} and name = #{newName}")
    File getByFileName(Long userId, String newName);
}
